<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二手易购</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #1a1a1a;
            --secondary: #333333;
            --accent: #666666;
            --light: #f5f5f5;
            --white: #ffffff;
            --dark: #000000;
            --light-gray: #e0e0e0;
            --medium-gray: #999999;
            --success: #28a745;
            --error: #dc3545;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        body {
            background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            display: flex;
            max-width: 1200px;
            width: 100%;
            background: var(--white);
            border-radius: 20px;
            overflow: hidden;
            box-shadow: var(--shadow);
            animation: fadeIn 1s ease-out;
            border: 1px solid var(--light-gray);
        }

        /* 功能特性区域 */
        .features-section {
            flex: 1;
            background: linear-gradient(135deg, var(--dark) 0%, #1a1a1a 100%);
            color: var(--light);
            padding: 50px 40px;
            position: relative;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            justify-content: center;
            border-right: 1px solid rgba(255, 255, 255, 0.05);
        }

        .features-section::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
            transform: rotate(30deg);
        }

        .features-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 25px;
            position: relative;
            z-index: 2;
        }

        .feature-card {
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 25px;
            transition: var(--transition);
            border: 1px solid rgba(255,255,255,0.05);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .feature-card:hover {
            transform: translateY(-5px);
            background: rgba(255, 255, 255, 0.08);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }

        .feature-icon {
            width: 50px;
            height: 50px;
            background: var(--secondary);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20px;
            font-size: 20px;
            color: var(--light);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
        }

        .feature-card h3 {
            font-size: 18px;
            margin-bottom: 12px;
            font-weight: 600;
            color: var(--light);
        }

        .feature-card p {
            font-size: 14px;
            line-height: 1.6;
            opacity: 0.8;
            color: var(--medium-gray);
        }

        /* 表单区域 */
        .form-section {
            flex: 1;
            padding: 50px 40px;
            position: relative;
            display: flex;
            flex-direction: column;
            justify-content: center;
            background: var(--white);
        }

        .form-container {
            max-width: 400px;
            width: 100%;
            margin: 0 auto;
        }

        .logo {
            text-align: center;
            margin-bottom: 40px;
        }

        .logo h1 {
            font-size: 32px;
            color: var(--dark);
            margin-bottom: 8px;
            letter-spacing: -0.5px;
        }

        .logo p {
            color: var(--medium-gray);
            font-size: 16px;
            font-weight: 300;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 24px;
            position: relative;
        }

        .form-control {
            width: 100%;
            height: 52px;
            padding: 0 20px;
            border: 1px solid var(--light-gray);
            border-radius: 10px;
            font-size: 15px;
            transition: var(--transition);
            background-color: var(--white);
            color: var(--dark);
            outline: none;
        }

        .form-control:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(102, 102, 102, 0.1);
        }

        .form-control::placeholder {
            color: var(--medium-gray);
            font-weight: 300;
        }

        .form-options {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 15px 0 25px;
        }

        .remember-me {
            display: flex;
            align-items: center;
            color: var(--medium-gray);
            font-size: 14px;
        }

        .remember-me input {
            margin-right: 8px;
            accent-color: var(--dark);
        }

        .forgot-password {
            color: var(--dark);
            text-decoration: none;
            transition: var(--transition);
            font-size: 14px;
            border-bottom: 1px solid transparent;
        }

        .forgot-password:hover {
            border-bottom: 1px solid var(--dark);
        }

        .btn {
            width: 100%;
            height: 52px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            letter-spacing: 0.5px;
        }

        .btn-dark {
            background: var(--dark);
            color: var(--white);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .btn-dark:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
            background: #111;
        }

        .social-login {
            text-align: center;
            margin: 25px 0;
            position: relative;
        }

        .social-login p {
            display: inline-block;
            background: var(--white);
            padding: 0 15px;
            position: relative;
            z-index: 2;
            color: var(--medium-gray);
            font-size: 14px;
        }

        .social-login::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: var(--light-gray);
            z-index: 1;
        }

        .social-icons {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 20px;
        }

        .social-btn {
            width: 46px;
            height: 46px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--white);
            border: 1px solid var(--light-gray);
            color: var(--medium-gray);
            font-size: 18px;
            transition: var(--transition);
        }

        .social-btn:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 15px rgba(0, 0, 0, 0.08);
            background: var(--dark);
            color: var(--white);
            border-color: var(--dark);
        }

        .auth-link {
            text-align: center;
            margin-top: 20px;
            color: var(--medium-gray);
            font-size: 14px;
        }

        .auth-link a {
            color: var(--dark);
            text-decoration: none;
            font-weight: 500;
            margin-left: 5px;
            transition: var(--transition);
            border-bottom: 1px solid transparent;
        }

        .auth-link a:hover {
            border-bottom: 1px solid var(--dark);
        }

        /* 动画 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .container {
                flex-direction: column;
                max-width: 600px;
            }

            .features-section {
                order: 2;
                padding: 30px 20px;
            }

            .form-section {
                order: 1;
                padding: 40px 20px;
            }

            .features-grid {
                grid-template-columns: 1fr;
            }
        }

        @media (max-width: 576px) {
            .form-options {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }

        /* 高级装饰元素 */
        .decoration-line {
            position: absolute;
            background: var(--light-gray);
            z-index: 0;
        }

        .line-1 {
            top: 30%;
            left: 0;
            width: 100%;
            height: 1px;
            opacity: 0.3;
        }

        .line-2 {
            top: 60%;
            left: 0;
            width: 100%;
            height: 1px;
            opacity: 0.3;
        }

        .decoration-dot {
            position: absolute;
            background: var(--light-gray);
            border-radius: 50%;
            z-index: 0;
            opacity: 0.2;
        }

        .dot-1 {
            width: 8px;
            height: 8px;
            top: 30%;
            right: 30px;
        }

        .dot-2 {
            width: 6px;
            height: 6px;
            top: 60%;
            left: 40px;
        }

        /* 响应消息 */
        .response-message {
            padding: 15px;
            border-radius: 10px;
            margin: 15px 0;
            text-align: center;
            display: none;
            font-size: 14px;
            font-weight: 500;
        }

        .error {
            background-color: rgba(220, 53, 69, 0.08);
            border: 1px solid var(--error);
            color: var(--error);
        }
    </style>
</head>
<body>
<!-- 登录页面 -->
<div class="container" id="loginPage">
    <!-- 功能特性区域 -->
    <div class="features-section">
        <div class="decoration-line line-1"></div>
        <div class="decoration-line line-2"></div>
        <div class="decoration-dot dot-1"></div>
        <div class="decoration-dot dot-2"></div>

        <h2 style="font-size: 28px; margin-bottom: 40px; text-align: center; font-weight: 600; position: relative; z-index: 3; color: var(--light);">为什么选择我们？</h2>

        <div class="features-grid">
            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3>安全交易</h3>
                <p>平台担保交易，资金托管保障，买卖双方权益全面保护，让您交易无忧。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-wallet"></i>
                </div>
                <h3>零手续费</h3>
                <p>免费发布商品，交易不收取任何手续费，让您的每一分钱都花在商品上。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-truck"></i>
                </div>
                <h3>便捷物流</h3>
                <p>一键发货，全国配送，物流状态实时跟踪，让商品快速到达买家手中。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-headset"></i>
                </div>
                <h3>客服支持</h3>
                <p>7×24小时专业客服团队，随时为您解决交易中的任何问题，提供贴心服务。</p>
            </div>
        </div>

        <div class="feature-card" style="margin-top: 30px; background: rgba(40, 167, 69, 0.08);">
            <h3 style="color: var(--success);"><i class="fas fa-gift"></i> 新用户福利</h3>
            <p>立即注册即可获得<span style="color: var(--success); font-weight: 600;">50元优惠券</span>，首单立减，超值优惠不容错过！</p>
        </div>
    </div>

    <!-- 登录表单区域 -->
    <div class="form-section">
        <div class="form-container">
            <div class="logo">
                <h1>二手易购</h1>
                <p>让闲置物品找到新主人</p>
            </div>

            <!-- 响应消息区域 -->
            <div class="response-message" id="responseMessage"></div>

            <div class="form-group">
                <input type="text" class="form-control" id="username" placeholder="用户名/手机号" required>
            </div>

            <div class="form-group">
                <input type="password" class="form-control" id="password" placeholder="密码" required>
            </div>

            <div class="form-options">
                <label class="remember-me">
                    <input type="checkbox" id="rememberMe"> 记住我
                </label>
                <a href="#" class="forgot-password">忘记密码?</a>
            </div>

            <button class="btn btn-dark" id="loginBtn">
                登录账号
            </button>

            <div class="auth-link">
                还没有账号? <a href="register.html">立即注册</a>
            </div>
        </div>
    </div>
</div>

<script>
    // 登录按钮事件
    document.getElementById('loginBtn').addEventListener('click', function() {
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        const responseElement = document.getElementById('responseMessage');

        if (!username || !password) {
            responseElement.textContent = '请输入用户名和密码';
            responseElement.className = 'response-message error';
            responseElement.style.display = 'block';
            return;
        }

        // 显示加载状态
        const originalText = this.innerHTML;
        this.innerHTML = '登录中...';
        this.disabled = true;

        // 调用后端登录接口（修改为/user/login路径）
        fetch('/user/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                username: username,
                password: password
            })
        })
            .then(response => {
                // 重置按钮状态
                this.innerHTML = '<i class="fas fa-sign-in-alt"></i> 登录账号';
                this.disabled = false;

                // 处理不同的响应状态
                if (response.ok) {
                    // 200 OK，登录成功
                    return response.json();
                } else if (response.status === 401) {
                    // 401 Unauthorized，用户名或密码错误
                    throw new Error('用户名或密码错误');
                } else {
                    // 其他错误状态
                    throw new Error('登录失败，请稍后再试');
                }
            })
            .then(data => {
                // 登录成功处理
                console.log('登录成功，用户信息:', data);



                // 存储用户信息到本地存储
                localStorage.setItem('userInfo', JSON.stringify(data));

                if (data.isAdmin) { // 直接使用后端返回的 isAdmin 字段
                    console.log('管理员登录，跳转到后台');
                    window.location.href = 'loginRoot.html';
                } else {
                    console.log('普通用户登录，跳转到商品首页');
                    window.location.href = 'productPage.html';
                }
            })
            .catch(error => {
                // 统一错误处理
                console.error('登录错误:', error);
                alert(error.message);
            });
    });

    // 输入框获得焦点时的效果
    const inputs = document.querySelectorAll('.form-control');
    inputs.forEach(input => {
        input.addEventListener('focus', function() {
            this.parentElement.style.transform = 'translateY(-2px)';
        });

        input.addEventListener('blur', function() {
            this.parentElement.style.transform = 'translateY(0)';
        });
    });



    // 页面加载完成事件
    document.addEventListener('DOMContentLoaded', function() {
        console.log("高级黑白色调登录页面加载完成");
    });
</script>
</body>
</html>